﻿using Dynamics.NAV.Metro.Common;
using Dynamics.NAV.Metro.Data;
using Okra.Core;
using Okra.Navigation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Contacts.Provider;

namespace Dynamics.NAV.Metro.Pages.GLAccounts
{
    public class GLAccountsViewModel : BindableBase
    {
        private IList<NavGLAccount> _glaccounts;
        
        public GLAccountsViewModel()
        {
            this.GoBackCommand = new DelegateCommand(GoBack);

            NavGLAccountDataSource navDataSource = new NavGLAccountDataSource();
            this.GLAccounts = navDataSource.GetGLAccounts();
        }

        [ImportingConstructor]
        public GLAccountsViewModel(INavGLAccountDataSource navDataSource)
        {
            this.GoBackCommand = new DelegateCommand(GoBack);

            this.GLAccounts = navDataSource.GetGLAccounts();
        }

        [Import]
        public INavigationManager NavigationManager { get; set; }
 
        public ICommand GoBackCommand { get; private set; }

        public bool CanGoBack
        {
            get { return NavigationManager.CanGoBack; }
        }

        public void GoBack()
        {
            NavigationManager.GoBack();
        }

        public NavCustomer SelectedGLAccount { get;  set; }

        public IList<NavGLAccount> GLAccounts
        {
            get
            {
                return _glaccounts;
            }
            set
            {
                if (_glaccounts != value)
                {
                    _glaccounts = value;
                    OnPropertyChanged("GLAccounts");
                }
            }
        }
    }
}
